#ifndef __CHANNEL_HPP_
#define __CHANNEL__HPP_

#include <iostream>
#include <string>
#include <unistd.h>

// 管道
class Channel
{
public:
    Channel(int wfd, pid_t who)
        : _wfd(wfd), _who(who)
    {
        // Channel-3-1203
        _name = "Channnel-" + std::to_string(wfd) + "-" + std::to_string(who);
    }
    std::string Name()
    {
        return _name;
    }
    ~Channel()
    {
    }
    // 发任务
    void Send(int cmd)
    {
        ::write(_wfd, &cmd, sizeof(cmd));
    }
    void Close()
    {
        ::close(_wfd);
    }
    pid_t Id()
    {
        return _who;
    }
    int Wfd()
    {
        return _wfd;
    }

private:
    int _wfd;          // 写端
    std::string _name; // 管道名字
    pid_t _who;        // 进程pid
};

#endif